package com.example.nit.controller;

import com.alibaba.fastjson.JSON;
import com.example.nit.whole.Reference;
import com.example.nit.bean.ValueCategory;
import com.example.nit.listener.SparkStreaming4Listener;
import com.example.nit.utils.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/spark4")
public class Streaming4Controller {
    @GetMapping("/qwer")
    public R qwer(){

        List<ValueCategory> result=new ArrayList<>();
        if (Reference.CurrentList!=null){
            for (String s : Reference.CurrentList) {
                try{
                    ValueCategory valueCategory = JSON.parseObject(s, ValueCategory.class);
                    result.add(valueCategory);
                }catch (Exception e){
                }
            }
            Reference.CurrentList.clear();
        }

        return R.ok().put("result",result);
    }

}
